package com.yanqu.road.dataHelper.action.excel;

import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.repair.BaseRepair;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author xx
 * @Date 2020/11/11
 */
public class User extends BaseRepair {

    public User(GameServer gameServer) {
        super(gameServer);
    }

    @Override
    public void repair(long param1, String param2) {

    }

    public void go(){
        List<Map<String, String>> dataList = new ArrayList<>();
        dataList = getUser();
        DataMgr.addData(dataList);
    }

    private List<Map<String, String>> getUser() {
        List<Map<String, String>> dataList = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "SELECT userId,titleId,nickName,vipExp,sex,earnSpeed,phonePlatform FROM t_u_user";
        try {
            call = getGameServer().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                String userId = checkNullToEmpty(rs.getString("userId"));
                Map<String,String> temp = new ConcurrentHashMap<>();
                temp.put("serverId",String.valueOf(getGameServer().getServerInfo().getServerId()));
                temp.put("userId",userId);
                temp.put("身份等级",checkNullToEmpty(rs.getString("titleId")));
                temp.put("角色昵称",checkNullToEmpty(rs.getString("nickName")));
                int sex = rs.getInt("sex");
                int phonePlatform = rs.getInt("phonePlatform");
                if(sex == 1){
                    temp.put("性别","男");
                }else if(sex == 2){
                    temp.put("性别","女");
                }else {
                    temp.put("性别","未知");
                }
                if(phonePlatform == 1){
                    temp.put("平台","安卓");
                }else if(phonePlatform == 2){
                    temp.put("平台","IOS");
                }else {
                    temp.put("平台","未知");
                }
                temp.put("vip经验",checkNullToEmpty(rs.getString("vipExp")));
                temp.put("赚速",checkNullToEmpty(rs.getString("earnSpeed")));
                dataList.add(temp);
            }
        } catch (SQLException ex) {
            getGameServer().getLogger().error("异常错误", ex);
        } finally {
            getGameServer().closeConnection(call, rs);
        }
        return dataList;
    }
}
